import dayjs from "dayjs";

export type FieldType = {
  time: string;
  num: number;
  isCircle: string;
  id?: number;
  holiday?: string;
};
const localK = "WENDU";
const timeForMat = "YYYY-MM-DD";

export const getDataList = () => {
  let tem = window.localStorage.getItem(localK);
  if (tem) {
    return JSON.parse(tem);
  }
  return [];
};
export const addData = (data: FieldType) => {
  let temp = { ...data };
  let allList = getDataList();
  if (temp.time) {
    const allTime = allList.map((item: FieldType) => {
      return item.time;
    });

    temp.time = dayjs(temp.time).format(timeForMat);
    if (allTime.includes(temp.time)) {
      return false;
    }
    allList.push(temp);
    localStorage.setItem(localK, JSON.stringify(allList));
  }

  return true;
};
